Imports XL.Common
Imports XL.Common.Utils

Public Class S_04_00201        
    Inherits XL.DB.Utils.BaseService
    Public Shared Function GetInstance() As S_04_00201                                           
                                                                                                 
        Dim result As S_04_00201                                                                 
        If AssetVisionXAuto.Decls.CURRENT_DB_TYPE = XL.DB.DBDecl.DBType.Remoting Then

            result = CType(Activator.GetObject(GetType(S_04_00201), _
                String.Format("tcp://{0}/S_04_00201.remote", _
                    SysInfo.ReadLocalSysInfo(CommDecl.XLSLVN_SYSTEM_REMOTE_SERVICE_URL))),  _
                S_04_00201)

            If result.ValidateAuthPassword(CommDecl.CURRENT_LOCAL_REMOTE_AUTH_PASSWORD) = False Then
                Dim ex As New XLException(XLException.ErrorClassify.ReadDataError)
                ex.SetMessage(CommDecl.MSG_ALERT_REMOTE_AUTH_DENIED)
                Throw ex
            End If

        Else

            result = New S_04_00201
        End If

        Return result

    End Function

    Public Enum LCs
        None
        Utld0002
        Utld0003
        Utld0004
        Utld0005
    End Enum


    Public Function ServLoadList( _
        ByVal valLoginStaffID As String, _
        ByVal valShowCompleted As Boolean, _
        ByRef refBindingExecutingTaskList As AssetVisionXAuto.FTs.FT_XV_T_AV_INVENTORY_TASK _
        ) As String
        Try
            Dim taskList As New AssetVisionXAuto.FTs.FT_XV_T_AV_INVENTORY_TASK
            Dim taskCondition As New AssetVisionXAuto.Facade.AfXV.ConditionOfXV_T_AV_INVENTORY_TASK(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            Dim taskStaffCondition As New AssetVisionXAuto.Facade.AfXV.ConditionOfXV_T_AV_INVENTORY_TASK(XL.DB.Utils.Condition.LogicOperators.Logic_Or)
            Dim taskStatusCondition As New AssetVisionXAuto.Facade.AfXV.ConditionOfXV_T_AV_INVENTORY_TASK(XL.DB.Utils.Condition.LogicOperators.Logic_Or)
            taskCondition.Add(taskStaffCondition, True)
            taskCondition.Add(taskStatusCondition, True)

            taskStaffCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.FUNCTIONARY__STAFF_IDColumn, "=", valLoginStaffID)
            taskStaffCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.PRINCIPAL__STAFF_IDColumn, "=", valLoginStaffID)
            taskStaffCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.EXECUTOR__STAFF_IDColumn, "=", valLoginStaffID)

            taskStatusCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_UNDERWAY)
            taskStatusCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_REVIEW)
            taskStatusCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_REPLACE_READY)

            'If valLoginStaffID.Length > 0 Then

            '    'Dim taskFunctionaryCondition As New AssetVisionXAuto.Facade.AfXV.ConditionOfXV_T_AV_INVENTORY_TASK(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            '    'Dim taskPrincipalCondition2 As New AssetVisionXAuto.Facade.AfXV.ConditionOfXV_T_AV_INVENTORY_TASK(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            '    'Dim taskStaffCondition3 As New AssetVisionXAuto.Facade.AfXV.ConditionOfXV_T_AV_INVENTORY_TASK(XL.DB.Utils.Condition.LogicOperators.Logic_And)

            '    'taskCondition.Add(taskSubCondition1, True)
            '    'taskCondition.Add(taskSubCondition2, True)
            '    'taskCondition.Add(taskSubCondition3, True)


            '    If valShowCompleted = True Then
            '        taskSubCondition1.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_COMPLETED)
            '        taskSubCondition1.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.FUNCTIONARY__STAFF_IDColumn, "=", valLoginStaffID)
            '        taskSubCondition2.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_COMPLETED)
            '        taskSubCondition2.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.PRINCIPAL__STAFF_IDColumn, "=", valLoginStaffID)
            '        taskSubCondition3.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_COMPLETED)
            '        taskSubCondition3.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.EXECUTOR__STAFF_IDColumn, "=", valLoginStaffID)
            '    Else

            '        'taskSubCondition2.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.PRINCIPAL_CONFIRMEDColumn, "=", False)
            '        'statusCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_UNDERWAY)
            '        'statusCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_REVIEW)

            '        'taskSubCondition3.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.PRINCIPAL_CONFIRMEDColumn, "=", True)
            '        'taskSubCondition3.Add(AssetVisionXAuto.Facade.AfXV.XV_T_AV_INVENTORY_TASKColumns.INVENTORY_STATUSColumn, "=", AssetVisionXAuto.Decls.CIVALUE_INVENTORY_STATUS_REPLACE_READY)
            '    End If

            'End If

            AssetVisionXAuto.Facade.AfXV.FillFT_XV_T_AV_INVENTORY_TASK(taskCondition, taskList)
            Dim locationTaskRows As New Dictionary(Of String, AssetVisionXAuto.FTs.FT_XV_T_AV_INVENTORY_TASKRow)

            For Each taskRow As AssetVisionXAuto.FTs.FT_XV_T_AV_INVENTORY_TASKRow In taskList
                locationTaskRows.Add(taskRow.LOCATION_ID, taskRow)
            Next

            Dim locationCondition As AssetVisionXAuto.Facade.AfBizMaster.ConditionOfM_AV_LOCATION = Facade.OpBizMaster.GetLocationConditionByStaffID(valLoginStaffID)
            Dim locationList As New AssetVisionXAuto.FTs.FT_M_AV_LOCATION

            AssetVisionXAuto.Facade.AfBizMaster.FillFT_M_AV_LOCATION(locationCondition, locationList)

            Dim refBindingExecutingTaskRow As AssetVisionXAuto.FTs.FT_XV_T_AV_INVENTORY_TASKRow
            refBindingExecutingTaskList.Clear()
            For Each locationRow As AssetVisionXAuto.FTs.FT_M_AV_LOCATIONRow In locationList

                refBindingExecutingTaskRow = refBindingExecutingTaskList.NewXV_T_AV_INVENTORY_TASKRow
                refBindingExecutingTaskList.AddXV_T_AV_INVENTORY_TASKRow(refBindingExecutingTaskRow)

                If locationTaskRows.ContainsKey(locationRow.LOCATION_ID) = True Then
                    refBindingExecutingTaskRow.CloneDataRow(locationTaskRows(locationRow.LOCATION_ID), True)

                    refBindingExecutingTaskRow.ROW_SELECTED = True
                Else
                    refBindingExecutingTaskRow.LOCATION_ID = locationRow.LOCATION_ID
                    refBindingExecutingTaskRow.LOCATION_NAME = locationRow.LOCATION_NAME
                    refBindingExecutingTaskRow.LOCATION_CODE = locationRow.LOCATION_CODE
                    refBindingExecutingTaskRow.PARENT_ID = locationRow.PARENT_ID
                    refBindingExecutingTaskRow.DEPARTMENT_ID = locationRow.DEPARTMENT_ID
                End If

            Next

            AssetVisionXService.Facade.OpBizMaster.RemoveLocationTreeUnselectedFromLeaf(refBindingExecutingTaskList, String.Empty, False)

            refBindingExecutingTaskList.UnselectAllRows()


        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty

    End Function


    Public Function ServBizUtld0002( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0002(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0003( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0003(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0004( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0004(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0005( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0005(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0006( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0006(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0007( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0007(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0008( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0008(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0009( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0009(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0010( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0010(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0011( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0011(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0012( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0012(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0013( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0013(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0014( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0014(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0015( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0015(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0016( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0016(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0017( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0017(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0018( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0018(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0019( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0019(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0020( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0020(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    End Class
